package com.brspace.qualitycontrol.utils;

import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import ma.glasnost.orika.metadata.ClassMapBuilder;

import java.util.Arrays;
import java.util.List;

/**
 * @author InTime
 */
public class BeanConvert<T, V> {

    public static MapperFactory getFactory() {
        return new DefaultMapperFactory.Builder().build();
    }

    public List<V> getFactory(List<T> sourceList, Class<V> targetClass, Class<T> sourceClass, String... ignoreAttribute) {
        List<String> ignoreList = ignoreAttribute != null ? Arrays.asList(ignoreAttribute) : null;
        DefaultMapperFactory build = new DefaultMapperFactory.Builder().build();
        ClassMapBuilder<V, T> builder = build.classMap(targetClass, sourceClass);
        for (String attribute : ignoreList) {
            builder.exclude(attribute);
        }
        builder.byDefault().register();
        return build.getMapperFacade().mapAsList(sourceList, targetClass);
    }

}
